package com.atguigu.dao;

import com.atguigu.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * CustomerDao
 *
 * @Author: 马伟奇
 * @CreateTime: 2021-02-22
 * @Description:
 *
 * <T, ID extends Serializable>
 *     T:表示dao接口，作用在哪个实体类身上
 *     ID:表示实体类主键id的类型
 *     HQL
 */
public interface CustomerDao extends JpaRepository<Customer,Long> {

    public List<Customer> findByCustName(String custName);

    @Query(value = "select * from cst_customer",nativeQuery = true)
    List<Customer> findAllCustomerSQL();


    @Query(value = "select * from cst_customer where cust_name like ?",nativeQuery = true)
    List<Customer> findCustNameLikeSQL(String custName);

    @Query(value = "select * from cst_customer where cust_name like ? and cust_industry = ?",nativeQuery = true)
    List<Customer> findCustNameLikeAndCustIndustrySQL(String custName, String custIndustry);

    @Query(value = "from Customer where custName like ? and custIndustry = ?")
    public List<Customer> findCustNameLikeAndCustIndustry(String custName,String custIndustry);

    /**
     * 根据名字进行模糊查询 like
     */
    @Query(value = "from Customer where custName like ?")
    public List<Customer> findCustNameLike(String name);


    /**
     * 自己实现SQL语句 查询所有
     * select * from cst_customer
     */
    @Query(value = "from Customer ")
    public List<Customer> findAllCustomer();
}

